home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / prog_c / cuj0696.zip / DWYER.ZIP / SPECTRAL.TST / XMOD.CX < prev    next >
Text File  |  1995-08-06  |  844b  |  33 lines

  1. /* ============ */
  2. /* xmod.cx    */
  3. /* ============ */
  4. #include <xtendefs.h>
  5. #include <stdio.h>
  6. #include <math.h>
  7. #include <stdlib.h>
  8. /* ==================================================================== */
  9. /* Xmod - Calculates remainder of XA / XB  (XA mod XB)            */
  10. /* ==================================================================== */
  11. void
  12. Xmod(USHORT *XA, USHORT *XB, USHORT *XREM)
  13. {
  14.     USHORT  MyXA[NE], MyXB[NE];
  15.     USHORT  Sign = (USHORT)(XTST(XA) > 0);
  16.  
  17.     XCOPY(XA, MyXA), XABS(MyXA);
  18.     XCOPY(XB, MyXB), XABS(MyXB);
  19.  
  20.     XDIV(MyXA, MyXB, XREM);        /* A / B -> XREM */
  21.     XFLOOR(XREM, XREM);            /* Integer Part  */
  22.     XRMULT(XREM, MyXB);            /* [A/B] * B     */
  23.  
  24.     if (Sign)
  25.     {
  26.     XSUB(MyXA, XREM, XREM);        /* + Remainder     */
  27.     }
  28.     else
  29.     {
  30.     XSUB(XREM, MyXA, XREM);        /* - Remainder     */
  31.     }
  32. }
  33.